<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="assets/css/font-awesome.min.css" />
    <!--[if IE 7]>
    <link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css" />
    <![endif]-->
    <link rel="stylesheet" href="assets/css/ace.min.css" />
    <link rel="stylesheet" href="assets/css/ace-rtl.min.css" />
    <link rel="stylesheet" href="assets/css/ace-skins.min.css" />
    <link rel="stylesheet" href="css/style.css"/>
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
    <![endif]-->
    <script src="assets/js/ace-extra.min.js"></script>
    <!--[if lt IE 9]>
    <script src="assets/js/html5shiv.js"></script>
    <script src="assets/js/respond.min.js"></script>
    <![endif]-->
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="assets/layer/layer.js" type="text/javascript"></script>
    <title>商家注册</title>
</head>

<body class="login-layout Reg_log_style">
<div class="logintop">
    <span>欢迎后台管理界面平台</span>
    <ul>
        <li><a href="#">返回首页</a></li>
        <li><a href="#">帮助</a></li>
        <li><a href="#">关于</a></li>
    </ul>
</div>
<div class="loginbody">
    <div class="login-container">
        <div class="center">
            <!--	     <img src="images/logo1.png" />-->
        </div>

        <div class="space-6"></div>
        <div class="position-relative">
            <div id="login-box" class="login-box widget-box no-border visible">
                <div class="widget-body">
                    <div class="widget-main">
                        <h4 class="header blue lighter bigger">
                            <i class="icon-coffee green"></i>
                            商家注册
                        </h4>

                        <div class="login_icon"><img src="images/login.png" width="140px" height="160px" style="position: relative;top: 20px"/></div>

                        <form class="">
                            <fieldset>
                                <ul>
                                    <li class="frame_style form_error"><label class="user_icon"></label><input name="用户名" type="text"  id="name"  placeholder="邮箱注册"/></li>
                                    <li class="frame_style form_error"><label class="password_icon"></label><input name="密码" type="password"   id="password" placeholder="包含大小写字母且数字不少于8位"/></li>
                                    <li class="frame_style form_error"><label class="password_icon"></label><input name="密码" type="password"   id="truePassword" placeholder="确认密码"/></li>
                                    <li class="frame_style form_error"><label class="Codes_icon"></label><input name="验证码" type="text"   id="emailCode" placeholder="邮箱验证码" style="width: 160px"/>
                                        <div class="Codes_region" style="position: absolute;height: 38px;
                                                    width: 80px;background-color: #428BCA;cursor: pointer" >
<!--                                            <div id="getEmailCode" style="width: 80px;-->
<!--                                                 height: 39px;-->
<!--                                                 cursor: pointer;-->
<!--                                                 background-color: rgb(66,139,202);" >点击获取</div>-->
                                            <button type="button"  id="getEmailCode"
                                                    style="position: relative;
                                                    height: 38px;
                                                    width: 80px;
                                                    top: 0px;
                                                    background-color: rgb(66,139,202);
                                                    cursor: pointer;
                                                    border: 0px;
                                                   ">
                                                点击获取
                                            </button>
                                        </div></li>

                                </ul>
                                <div class="space">
                                </div>

                                <div class="clearfix">
                                    <label class="inline">
                                        <input type="checkbox" class="ace">
<!--                                        <span class="lbl">保存密码</span>-->
                                    </label>
                                    <button type="button" class="width-35 pull-right btn btn-sm btn-primary" id="register_btn" >
                                        <i class="icon-key"></i>
                                        注册
                                    </button>
                                </div>

                                <div class="space-4"></div>
                            </fieldset>
                        </form>

                        <div class="social-or-login center">
                            <span class="bigger-110">通知</span>
                        </div>

                        <div class="social-login center">
                            本网站系统不再对IE8以下浏览器支持，请见谅。
                        </div>
                    </div><!-- /widget-main -->

                    <div class="toolbar clearfix">
                    </div>
                </div><!-- /widget-body -->
            </div><!-- /login-box -->
        </div><!-- /position-relative -->
    </div>
</div>
<div style="position: absolute;left:50%;margin-left:150px;top:160px"><a href="login.html">返回登录</a></div>
<div class="loginbm">版权所有  2021  <a href="">卓景京信息技术有限公司</a> </div><strong></strong>
</body>
<script>
    $('#getEmailCode').on('click', function() {
        var shopName = $("#name").val();
        var shopPassword = $("#password").val();
        var truePassword=$("#truePassword").val();
        var emailCode = $("#emailCode").val();
        if (shopName == "" || shopName == null) {
            layer.msg('邮箱不能为空!', {icon: 1, time: 1500});
            return;
        }
        if (shopPassword == "" || shopPassword == null) {
            layer.msg('密码不能为空!', {icon: 1, time: 1500});
            return;
        }
        if (truePassword == "" || truePassword == null) {
            layer.msg('确认密码不能为空!', {icon: 1, time: 1500});
            return;
        }
        if (shopPassword!=truePassword){
            layer.msg('前后密码不一致!', {icon: 1, time: 1500});
            return;
        }
        $.ajax({
            url: "http://localhost:8080/SnacksShop/boss.do?type=getEmailCode",
            data: {
                shopName: shopName
            },
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            type: "post",
            success: function (data) {
                console.log(data);
                if (data == "emailError") {
                    layer.msg('该邮箱已经注册!', {icon: 1, time: 1500});
                    $("#name").val("");
                    $("#password").val("");
                    $("#truePassword").val("");
                    $("#emailCode").val("");
                }
                if(data=="true"){
                    layer.msg('获取成功!', {icon: 1, time: 1500});
                }
            },
            error: function (data) {
                layer.msg('请检查你的网络!', {icon: 1, time: 1500});
            }
        })
    });

    $('#register_btn').on('click', function() {
        var shopName = $("#name").val();
        var shopPassword = $("#password").val();
        var truePassword=$("#truePassword").val();
        var emailCode = $("#emailCode").val();

        if (shopName == "" || shopName == null) {
            layer.msg('邮箱不能为空!', {icon: 1, time: 1500});
            return;
        }
        if (shopPassword == "" || shopPassword == null) {
            layer.msg('密码不能为空!', {icon: 1, time: 1500});
            return;
        }
        if (truePassword == "" || truePassword == null) {
            layer.msg('确认密码不能为空!', {icon: 1, time: 1500});
            return;
        }
        if (emailCode == "" || emailCode == null) {
            layer.msg('邮箱验证码不能为空!', {icon: 1, time: 1500});
            return;
        }
        var   re =/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/;
        var result=  re.test(shopPassword);
        if(result)
        {}else {
            layer.msg('密码格式不正确', {icon: 1, time: 1500});
            return;
        }
        if (shopPassword!=truePassword){
            layer.msg('前后密码不一致!', {icon: 1, time: 1500});
            return;
        }
        $.ajax({
            url: "http://localhost:8080/SnacksShop/boss.do?type=shopRegister",
            data: {
                shopName: shopName,
                shopPassword: shopPassword,
                truePassword: truePassword,
                emailCode:emailCode
            },
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            type: "post",
            success: function (data) {
                console.log("注册:"+data);
                if (data == "codeError") {
                    layer.msg('邮箱验证码错误!', {icon: 1, time: 1500});
                    $("#emailCode").val("");
                }
                if (data == "userError") {
                    layer.msg('注册失败!', {icon: 1, time: 1500});
                    $("#emailCode").val("");
                }
                if (data=="true") {
                    layer.msg('注册成功!', {icon: 1, time: 1500});
                    // layer.alert("注册成功", {icon: 1, title: '提示框'});
                    setTimeout(function (){
                        location.href = "./login.html";
                    },1500);
                }
            },
            error: function (data) {
                layer.msg('请检查你的网络!', {icon: 1, time: 1500});
            }
        })
    });
</script>
</html>

